﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ExpressionUtil.Common
{
    /// <summary>
    /// 字符串助手类
    /// </summary>
    internal static class StringHelper
    {
        /// <summary>
        /// 检查是否是运算符字符
        /// </summary>
        /// <param name="character">需要检查的字符</param>
        /// <returns>是否是运算符字符</returns>
        public static bool IsOperatorChar(char character)
        {
            return character == '+' || character == '-' || character == '*' || character == '/' ||
                character == '>' || character == '<' || character == '=' || 
                character == '&' || character == '|' || character == '!'||
                character == '~' || character == ',';
        }

        /// <summary>
        /// 检查是否是一元运算符字符
        /// </summary>
        /// <param name="character">需要检查的字符</param>
        /// <returns>是否是非一元运算符字符</returns>
        public static bool IsUnitaryOperatorChar(char character)
        {
            return character == '-' || character == '+' ||
                character == '~' || character == '!';
        }

        /// <summary>
        /// 检查是否是非一元运算符字符
        /// </summary>
        /// <param name="character">需要检查的字符</param>
        /// <returns>是否是非一元运算符字符</returns>
        public static bool IsNoneUnitaryOperatorChar(char character)
        {
            return character == '*' || character == '/' ||
                character == '>' || character == '<' || character == '=' ||
                character == '&' || character == '|' || character == ',';
        }

        /// <summary>
        /// 检查是否是特殊字符
        /// </summary>
        /// <param name="character">需要检查的字符</param>
        /// <returns>是否是特殊字符</returns>
        public static bool IsSpecialChar(char character)
        {
            return character == '(' || character == ')' || character == ',';
        }

        /// <summary>
        /// 检查是否是空格字符
        /// </summary>
        /// <param name="character">需要检查的字符</param>
        /// <returns>是否是空格字符</returns>
        public static bool IsSpaceChar(char character)
        {
            return character.Equals('\n') || character.Equals(' ') || character.Equals('\t') || character.Equals('\r');
        }

        /// <summary>
        /// 替换指定字符串中得空字符串
        /// </summary>
        /// <param name="data">需要替换的字符串</param>
        /// <returns>替换的结果</returns>
        public static string ReplaceSpaceChar(string data)
        {
            if (string.IsNullOrEmpty(data))
            {
                return data;
            }
            else
            {
                return data.Replace("\n", string.Empty).Replace(" ", string.Empty).Replace("\t", string.Empty).Replace("\r", string.Empty);
            }
        }
    }
}
